import JSEncrypt from "./jsencrypt.min.js"

// const encryptor = new JSEncrypt({ default_key_size: 1024 })
/**
 * RSA非对称加密与解密方法
 */
/**
 * @description 生成公钥和私钥
 * @author WangSLi
 * @param {*} publicKey 公钥
 * @param {*} data 数据
 */
export function generateKey() {
  const genKeyPair = {}
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt()
  // 获取私钥
  genKeyPair.privateKey = encryptor.getPrivateKey()
  // 获取公钥
  genKeyPair.publicKey = encryptor.getPublicKey()
  return genKeyPair
}

/**
 * @description 数据加密方法
 * @author WangSLi
 * @param {*} publicKey 公钥
 * @param {*} data 数据
 */
export function encryptedData(plain, publicKey) {
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt()
  // 设置公钥
  encryptor.setPublicKey(publicKey)
  // 加密数据
  return encryptor.encrypt(plain)
}

/**
 * @description 数据解密方法
 * @author WangSLi
 * @param {*} publicKey 公钥
 * @param {*} data 数据
 */
export function decryptedData(cipher, privateKey) {
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt()
  // 设置公钥
  encryptor.setPrivateKey(privateKey)
  // 加密数据
  return encryptor.decrypt(cipher)
}

export function privateKey(){
	return  'MIICWwIBAAKBgFqzR6JkQbgejIaucUzi1lMNkmFsVyibHguT6sKNVZDX8eEaoR40' +
		'M9DboCm3bUoZ/EXcGHlglT7pl+VE3sWQYGIY+cOowz9W2tS6pQItgzVMp9Dx90Pz' +
		'PcCwY/PAAFkXuFHs07cMe2U/e0lFI6hJaoUwHeZNGJoiUYM8cITgFhzJAgMBAAEC' +
		'gYBAecmmixacyDqlU0R/n5E0ISW508ZxuzM0j8YG32nAOYJcvw1h50IeasIEZbxv' +
		'POG0160eO6ZcvrmX5clnMCcTO6lzn4Y68dQfLc8ObfuLd1HR1iOAfLgu8rTj1RDF' +
		'dsOmdVbRmM6sGbsxduFmzcMRd+713Ck/omysfdVxcS0fwQJBAKZpwJXO985Id/y0' +
		'vi4t/x3IIQV+4a3i/jiW56WI5QOf8FR3r1hUIWBBDStttiDJhUBgR+5JWGp1Ek7V' +
		'DLsNPU0CQQCLhyh03VGfN1aC0oDl5Ck4oDPvbiB2O/IVIlC8Y6hZaeuDfli5RfGv' +
		'17mpBqWbdrFR4O40yfXu60iUzD8oiY9tAkEAnH/9xqUytQPAG57a79EACEEKlQGD' +
		'OaWs0QlR5oI8ZdFHEhjQhS/xh3UF7p6p1mHOeAFUBEtj5BIfWpXP+CV2TQJAMDPc' +
		'XStMlHW4tG9myoUdXIu0BYaFPnONOZHmVH8VXPaDv6S5oCAy0+3yHRvHwMKrlb7g' +
		'bGpNRWIRbB53v1hurQJADrWxnDw0Ie5IeXQ6LZIrMc5BO5IRFq1W71kNXYYGXbbl' +
		'Tkx9dh527c5CTCc7/IXdEdqCFB7Ubzh75kdoiWKDSg=='
}
